<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }
        .hide{
            display: none;
        }
        .c1{
            position: fixed;
            top:0;
            bottom: 0;
            left:0;
            right:0;
            background-color: #1b1616;
            opacity:0.6;
            z-index:9;
        }
        .c2{
            width: 500px;
            height:400px;
            background-color: white;
            position: fixed;
            left: 50%;
            top:50%;
            margin-left: -250px;
            margin-top: -200px;
            z-index:10;
        }
    </style>
</head>
<body>

    <div>
        <input type="button" value="添加" onclick="ShowModel();">
        11111
    </div>
    <!--遮罩层开始-->

    <div id='i1' class="c1 hide" onclick="HideModel();"></div>  <!--在空白处点击弹框也消失-->
    <!--遮罩层结束-->
    <!--弹出框开始-->
    <div id="i2" class="c2 hide">
        <div id="i3">
            <p><input type="text"></p>
            <p><input type="text"></p>
        </div>
        <p>
            <input type="button" value="取消" onclick="HideModel();">
            <input type="button" value="确定" onclick="HideModel();">
        </p>
    </div>
    <!--弹出框结束-->


    <script>
        function cleardata() {
            //获取两个p标签
            var ptag = document.getElementById('i3').children
            for(i=0;i<ptag.length;i++){
                ptag[i].children[0].value=''
            }
        }


        function ShowModel() {
            document.getElementById('i1').classList.remove('hide');
            document.getElementById('i2').classList.remove('hide');
        }
        function HideModel() {
//            todo初始化输入框,将id=i3内的input输入内容清空
            cleardata()
            document.getElementById('i1').classList.add('hide');
            document.getElementById('i2').classList.add('hide');
        }
    </script>
</body>
</html>